{extend name="common/base" /}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">

                        <div class="layui-card-body">
                            {include file="user/adminform" /}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="my_js"}
<script>
    layui.use(['element', 'admin', 'form'], function () {
        var element = layui.element
            , admin = layui.admin
            , $ = layui.$
            , form = layui.form;
        var id = {$id};
        admin.ajax('admin/user/admin/' + id, '', function (udata) {
            admin.ajax('admin/group', '', function (data) {
                if (data.code == 1001) {
                    $.each(data.data, function (index, value) {
                        $('select[name="group_id"]').append('<option value="' + value.id + '">' + value.title + '</option>');
                    })
                    form.render('select');
                    $('input[name="user_pass"]').val('');
                    form.val('', udata.data);
                } else {
                    layer.msg(data.msg + '请联系管理员。');
                }
            }, '', 'get');
        }, '', 'get');
        form.verify({
            user_login: function (value) {
                if (value == '') {
                    return '用户名不能为空';
                }
                var res = admin.isUserLogin(value);
                return res;
            }
            , user_email: function (value) {
                if (value != '') {
                    var res = admin.isEmail(value);
                    return res;
                }
            }
            , mobile: function (value) {
                if (value != '') {
                    var res = admin.isMobile(value);
                    return res;
                }
            }
            , user_pass: function (value) {
                if (value != '') {
                    var res = admin.isUserPass(value);
                    return res;
                }
            }
        });
        form.on('submit(formAdmin)', function (data) {
            data.field.status = data.field.status ? data.field.status : 0;
            admin.ajax('admin/user/admin/' + id, data.field, function (data) {
                if (data.code == 1001) {
                    $('#layui-icon-refresh',parent.document).click();
                    layer.confirm(data.msg + ',是否返回?', {
                        icon: 3,
                        title: '提示',
                        btn: ['留下', '返回']
                    }, function (index) {
                        location.reload();
                    }, function () {
                        admin.closeSelf()
                    });
                } else {
                    layer.msg(data.msg);
                }
            }, '', 'PUT');
        });
    });
</script>
{/block}